//
//  CancellationCardViewController.m
//  MyWallet
//
//  Created by 小肥羊 on 15/7/16.
//  Copyright (c) 2015年 小肥羊. All rights reserved.
//

#import "CancellationCardViewController.h"

@interface CancellationCardViewController ()

@end

@implementation CancellationCardViewController

#pragma mark - Set
- (void)setCancellationDate:(NSDate *)cancellationDate
{
    _cancellationDate = cancellationDate;
    NSDateFormatter *dateformatter = [[NSDateFormatter alloc] init];
    [dateformatter setDateFormat:@"YYYY-MM-dd HH:mm"];
    NSString *locationString=[dateformatter stringFromDate:_cancellationDate];
    [self.changeDateButton setTitle:locationString forState:UIControlStateNormal];
}

#pragma mark - 初始化
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.selectDateView = [[SelectDateView alloc] initWithDelegate:self];
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    NSString *cardIndex = [self.receiveDict objectForKey:@"cardIndex"];
    CardModel *card = [[TotalAssets sharedManager] cardWithIndexString:cardIndex];
    [self.card upCard:card];
    [self.card.activationButton setHidden:YES];
    self.cancellationDate = [NSDate date];
    [self.changeDateButton.layer setCornerRadius:kNomalRadius];
}



#pragma mark - 切换原因
- (IBAction)changeReason:(UISwitch *)sender {
    if (sender.isOn) {
        [self.reasonLabel setText:@"转到钱包中"];
    } else {
        [self.reasonLabel setText:@"直接注销"];
    }
}

#pragma mark - 完成
- (IBAction)finishCancellationCard:(UIBarButtonItem *)sender {
    NSString *cardIndex = [self.receiveDict objectForKey:@"cardIndex"];
    if ([self.reasonLabel.text isEqualToString:@"转到钱包中"]) {
        [[TotalAssets sharedManager] cancellationCard:cardIndex RecordDate:self.cancellationDate toWalletMoney:YES];
    } else {
        [[TotalAssets sharedManager] cancellationCard:cardIndex RecordDate:self.cancellationDate toWalletMoney:NO];
    }
    [self.navigationController popViewControllerAnimated:YES];
}

#pragma mark - 修改时间
- (IBAction)changeDate:(UIButton *)sender {
    [self.view endEditing:YES];
    [ActionView showView:self.selectDateView direction:PopViewDirectionStyleCenter];
}

#pragma mark - 时间选择代理
- (void)selectDate:(SelectDateView *)picker
{
    self.cancellationDate = picker.datePicker.date;
    [[NSNotificationCenter defaultCenter] postNotificationName:CLOESNOTICE object:picker];
}
- (void)cancelSelect:(SelectDateView *)picker
{
    [[NSNotificationCenter defaultCenter] postNotificationName:CLOESNOTICE object:picker];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
